package com.iterator.controller.wechat.dhy;

import com.iterator.bean.web.pojo.BaseRespVo;
import com.iterator.bean.wechat.dhy.DetailListVO;
import com.iterator.bean.wechat.dhy.GoodsCategoryVO;
import com.iterator.bean.wechat.dhy.GoodsListVO;
import com.iterator.bean.wechat.dhy.RelatedGoods;
import com.iterator.service.wechat.dhy.WxGoodsService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: DHY
 * @Date: 2021/1/12 15:24
 * @Description: wx 商品相关
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    WxGoodsService wxGoodsService;


    /**
     * 商品页面数量显示
     * @return
     */
    @GetMapping("count")
    public BaseRespVo showGoodsCount() {
        Map<String,Integer> count= wxGoodsService.showGoodsCount();
        return BaseRespVo.ok(count);
    }

    /**
     * 显示具体商品页面
     * @param id
     * @return
     */
    @GetMapping("category")
    public BaseRespVo showCategory(Integer id) {
        GoodsCategoryVO goodsCategoryVO=wxGoodsService.showCategory(id);
        return BaseRespVo.ok(goodsCategoryVO);
    }

    /**
     * 商品显示
     * @param categoryId
     * @param page
     * @param size
     * @return
     */
    @GetMapping("list")
    public BaseRespVo showList(Integer categoryId,Integer page,Integer size,String keyword,String sort,String order,Integer brandId) {
        String username = (String) SecurityUtils.getSubject().getPrincipal();
        GoodsListVO goodsListVO=wxGoodsService.showList(categoryId,page,size,keyword,sort,order,brandId,username);
        return BaseRespVo.ok(goodsListVO);
    }

    /**
     * 商品详细信息显示
     * @return
     */
    @GetMapping("detail")
    public BaseRespVo showDetailList(Integer id) {
        SecurityUtils.getSubject().getSession().setAttribute("GoodsId",id);
        DetailListVO detailListVO =wxGoodsService.showDetailList(id);
        return BaseRespVo.ok(detailListVO);
    }

    /**
     * 相关商品推荐
     * @param id
     * @return
     */
    @GetMapping("related")
    public BaseRespVo showRelatedGoods(Integer id) {
        List<RelatedGoods> relatedGoods=wxGoodsService.showRelatedGoods(id);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("goodsList",relatedGoods);
        return  BaseRespVo.ok(objectObjectHashMap);
    }
}
